//
//  WBUserAccount.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/10.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "WBUserAccount.h"

@interface WBUserAccount ()<NSCoding>

@end


@implementation WBUserAccount

- (void)setExpires_in:(int)expires_in
{
    
    _expires_in = expires_in;
    
    self.expires_date = [NSDate dateWithTimeIntervalSinceNow:_expires_in];

}





- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    if(self = [super init])
    {
        [self setValuesForKeysWithDictionary:dict];
    
    }

    return self;

}

+ (instancetype)accountWithDictionary:(NSDictionary *)dict
{

    return [[self alloc] initWithDictionary:dict];

}
//字典转模型 防止报错
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{

}

//归档
- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.screen_name forKey:@"screen_name"];
    [aCoder encodeObject:self.avatar_large forKey:@"avatar_large"];
    [aCoder encodeObject:self.expires_date forKey:@"expires_date"];

}


//解档
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if(self = [super init])
    {
        self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
        self.screen_name = [aDecoder decodeObjectForKey:@"screen_name"];
        self.avatar_large = [aDecoder decodeObjectForKey:@"avatar_large"];
        self.expires_date = [aDecoder decodeObjectForKey:@"expires_date"];
        
  
    }

    return self;

}










- (NSString *)description
{

    return [NSString stringWithFormat:@"%@,access_token = %@,expires_date = %@, uid = %@ , screen_name = %@ , avatar_large = %@",[super description],self.access_token,self.expires_date,self.uid,self.screen_name,self.avatar_large];

}

@end
